package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZcVehicles;
import com.ruoyi.system.service.IZcVehiclesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租车车辆Controller
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@Controller
@RequestMapping("/system/vehicles")
public class ZcVehiclesController extends BaseController
{
    private String prefix = "system/vehicles";

    @Autowired
    private IZcVehiclesService zcVehiclesService;

    @RequiresPermissions("system:vehicles:view")
    @GetMapping()
    public String vehicles()
    {
        return prefix + "/vehicles";
    }

    /**
     * 查询租车车辆列表
     */
    @RequiresPermissions("system:vehicles:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZcVehicles zcVehicles)
    {
        startPage();
        List<ZcVehicles> list = zcVehiclesService.selectZcVehiclesList(zcVehicles);
        return getDataTable(list);
    }

    /**
     * 导出租车车辆列表
     */
    @RequiresPermissions("system:vehicles:export")
    @Log(title = "租车车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZcVehicles zcVehicles)
    {
        List<ZcVehicles> list = zcVehiclesService.selectZcVehiclesList(zcVehicles);
        ExcelUtil<ZcVehicles> util = new ExcelUtil<ZcVehicles>(ZcVehicles.class);
        return util.exportExcel(list, "租车车辆数据");
    }

    /**
     * 新增租车车辆
     */
    @RequiresPermissions("system:vehicles:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存租车车辆
     */
    @RequiresPermissions("system:vehicles:add")
    @Log(title = "租车车辆", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZcVehicles zcVehicles)
    {
        return toAjax(zcVehiclesService.insertZcVehicles(zcVehicles));
    }

    /**
     * 修改租车车辆
     */
    @RequiresPermissions("system:vehicles:edit")
    @GetMapping("/edit/{vehicleId}")
    public String edit(@PathVariable("vehicleId") Long vehicleId, ModelMap mmap)
    {
        ZcVehicles zcVehicles = zcVehiclesService.selectZcVehiclesByVehicleId(vehicleId);
        mmap.put("zcVehicles", zcVehicles);
        return prefix + "/edit";
    }

    /**
     * 修改保存租车车辆
     */
    @RequiresPermissions("system:vehicles:edit")
    @Log(title = "租车车辆", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZcVehicles zcVehicles)
    {
        return toAjax(zcVehiclesService.updateZcVehicles(zcVehicles));
    }

    /**
     * 删除租车车辆
     */
    @RequiresPermissions("system:vehicles:remove")
    @Log(title = "租车车辆", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zcVehiclesService.deleteZcVehiclesByVehicleIds(ids));
    }
}
